<template>
	<view class="content">
		<video-header @setTitle='setTitle' :isBoolean='isBoolean' :actIndex='actIndex' @setIndex='setIndex'
			:isFlag='isFlag'></video-header>
<!-- 			<videoop v-if="isFlag" :cateId='cateId' @setFollow='setFollow' :area='location' :isFlag='isFlag'
						:allList='videoArray' :playIndex='playIndex' @updateList='bottomScroll' :videoArray='List'></videoop> -->
<!-- 		<videonue v-if="isFlag" @func="getMsgFormSon" :isshow='true' :videoArray='List' :cateId='cateId'
			@setFollow='setFollow' :area='location' :isFlag='isFlag' :playIndex='playIndex' @updateList='bottomScroll'>
		</videonue> -->
		<!-- <scroll-view class='scroll_box' scroll-y='true' @scrolltolower='bottomScroll' v-else>
		<videonue v-if="show" @func="getMsgFormSon" :isshow='true' :videoArray='List' :cateId='cateId' @setFollow='setFollow' :area='location' :isFlag='isFlag' :allList='videoArray' :playIndex='playIndex' @updateList='bottomScroll'></videonue>
					<uniLoadMore :loadingType='loadingType'></uniLoadMore>
		</scroll-view> -->
		<view  style="width: 100%;height: 100%;">
			<videonues v-if="show && videoArray.length>0" @func="getMsgFormSon" :isshow='true' :videoArray='List'
				:cateId='cateId' @setFollow='setFollow' :area='location' :isFlag='isFlag' :allList='videoArray'
				:playIndex='playIndex' @updateList='bottomScroll'></videonues>
			<uniLoadMore :loadingType='loadingType' v-else></uniLoadMore>
		</view>
	</view>

	<!-- <videoTabList ref="tabList" :list='videoArray' @playVideo='playVideo'></videoTabList> -->
	<!-- <videonues :isshow='true' :videoArray='List' :cateId='cateId' @setFollow='setFollow' :area='location' :isFlag='isFlag'
		:allList='videoArray' :playIndex='playIndex' @updateList='bottomScroll'></videonues> -->
</template>

<script>
	import videoHeader from "../../components/video/videoHeader.vue"
	import videoop from "../../components/videoList/viedeop.vue"
	import videonue from '../../components/video/videonvue.nvue'
	import videonues from '../../components/video/videonvues.nvue'
	import videoList from "../../components/video/videoList.vue"
	import videoTabList from "../../components/videoTabList"
	import * as utils from '../../utils/index.js'
	import uniLoadMore from "../../components/uni-load-more.vue"
	export default {
		data() {
			return {
				actIndex: -1,
				cateId: 0,
				location: {},
				page: 1,
				List: [],
				isFlag: true,
				playIndex: 0,
				show: false,
				loadingType: 0,
				isBoolean: 1,
				videoArray: [],
				isShow: true,
				userinfo: {},
				userid: ''
			}
		},
		onLoad() {
			this.isFlag = true
		},
		onShow() {
			this.isFlag = true
		},
		created() {
			if (this.videoArray.length == 0) {
			
				this.getList(1)
			}
			// alert(456)
			// console.log(1111111111,this.show)
			// uni.showLoading({
			// 	title: '请求中'
			// })
			this.userInfo = this.$store.getters.getuserInfo || {}
			// #ifdef MP-WEIXIN
			utils.authorizedPositioning((msg, res) => {
				if (msg == 'Authorized') {
					// console.log(msg)
					// console.log(res)
					// console.log('chufa')
					this.location = res
					this.$store.commit('setLocation', res)
					// this.getList(1)
				} else {

				}

			})

			// #endif
			//  #ifndef  MP-WEIXIN 
			this.isFlag = true
			
			// #endif 
			// #ifdef APP-PLUS
			// this.isFlag = true
			this.isFlag = true
			// this.getList(1)
			// #endif
		},
		onTabItemTap() {
			// alert(777)
			this.isFlag = true
		},
		onHide() {
			this.isFlag = false
			this.show = false
			// this.List = []
			// this.videoArray = []
			// uni.createVideoContext('myVideo',this).pause()
			// console.log(11111111111)
			// alert(this.show,"s555")
		},
		onShow() {
			// alert(this.show,"s5558")
			this.isFlag = true
			console.log("Sadasda")
			// this.show = true
		},
		methods: {
			getMsgFormSon(data) {
				// this.msgFormSon = data
				this.getList(data)
				this.setDelList(this.videoArray)
			},

			setFollow(id) {
				console.log()
				this.List = this.List.map(item => {
					if (item.shop_id == id) {
						// console.log(item)
						item.is_follow = item.is_follow == 0 ? 1 : 0
					}
					return item
				})
			},
			setIndex(e) {
				console.log(e, "头部触发1111")

				this.actIndex = e.index
				this.isBoolean = 0
				this.cateId = e.id
				this.isFlag = false
				this.show = true
				this.List = []
				this.videoArray = []
				this.getList(1)
			},
			setTitle(index) {
				console.log(index, "头部触发22222")
				this.isBoolean = index
				if (index == 2) {
					this.isFlag = false
					// this.show = false
				} else {
					this.isFlag = true
					// this.show = true
				}
				this.actIndex = -1
				this.cateId = 0

				this.videoArray = []
				this.List = []
				// this.$refs.tabList.refresh()
				this.getList(1)
			},
			//数组去重
			setDelList(arr) {
				return Array.from(new Set(arr))
			},
			getList(page) {
				// alert(123)
				var id = ''
				if (this.userInfo == '') {

				} else {
					this.userid = this.userInfo.id
					id = this.userInfo.id
				}
				// uni.request({
				// 	url: 'https://dsx.cdzer.com/api/Video/getVideoList', //仅为示例，并非真实接口地址。
				// 	data: {
				// 		uid: id,
				// 		page: page,
				// 		cate_id: this.cateId,
				// 		lat: 28.227404,
				// 		lng: 112.905383,
				// 		titleIndex: this.isBoolean
				// 	},
				// 	method: 'POST',
				// 	header: {
				// 		'content-type': 'application/x-www-form-urlencoded',
				// 	},
				// 	success: (res) => {
				// 		// console.log(res,"视频列表")
				// 		if (res.data.status == 200) {
				// 			if (res.data.data.video_list.length == 0) {
				// 				--page
				// 				this.loadingType = 3
				// 			}
				// 			if (res.data.data.video_list.length > 0) {
				// 				this.List = this.List.concat(res.data.data.video_list)
				// 				this.videoArray = this.videoArray.concat(res.data.data.video_list)
				// 				this.page = page
				// 			}


				// 		}
				// 	}
				// });
			},
			playVideo(index) {
				this.playIndex = index
				this.isFlag = true
			},
			bottomScroll() {
				this.loadingType = 1
				this.getList(++this.page)
			}
		},
		components: {
			videoList,
			videoHeader,
			videoTabList,
			uniLoadMore,
			videoop,
			videonue,
			videonues
			// videoFooter
		},
		onShow() {
			try {
				const value = uni.getStorageSync('userInfo');
				if (value) {

					this.userInfo = JSON.parse(value)
				} else {
					this.userInfo = ''
				}
			} catch (e) {
				// error
			}
			this.isFlag = true
			// this.location = this.$store.getters.getLocation || {}
			let pages = getCurrentPages();
			let currPage = pages[pages.length - 1];
			// if (currPage.data.isDoRefresh == true) {
			// 	currPage.data.isDoRefresh = false;
			// 	this.doRefresh();
			// } else {
			// 	//不用刷新
			// }
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;
		height: 100%;
		overflow: hidden;
		color: #3F536E;
		background-color: #000000;

		.title {
			margin: 0 20rpx;
		}
	}

	.scroll_box {
		height: calc(100vh - 288rpx);
		// margin-top: ;
		width: 100%;
		margin: 58rpx 0vw;
	}
</style>
